<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<base href="<%=basePath%>" />
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>供货商表单</title>
		<link rel="stylesheet" href="res/layui/css/layui.css">
		<script src="res/js/jquery-2.1.4.min.js" type="text/javascript"></script>
		<script src="res/layui/layui.js"></script>
	</head>
	<body style="padding: 40px 40px 0px 40px">
		<form class="layui-form" id="Apply">
			<input type="hidden" id="applyId" name="applyId">
			<div class="layui-form-item">
				<label class="layui-form-label">供货商编码</label>
				<div class="layui-input-block">
					<input type="text" id="applyNumber" name="applyNumber" lay-verify="required"
						autocomplete="off" placeholder="请输入供货商编码" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">供货商名称</label>
				<div class="layui-input-block">
					<input type="text" id="applyName" name="applyName" lay-verify="required"
						placeholder="请输入供货商名称" autocomplete="off" class="layui-input">
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">联系电话</label>
				<div class="layui-input-block">
					<input type="text" id="applyPhone" name="applyPhone" lay-verify="required"
						placeholder="请输入联系电话" autocomplete="off" class="layui-input">
				</div>
			</div>
			
			
			<div class="layui-form-item">
				<label class="layui-form-label">负责人</label>
				<div class="layui-input-block">
					<input type="text" id="applyBoss" name="applyBoss" lay-verify="required"
						placeholder="请输入负责人姓名" autocomplete="off" class="layui-input">
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">邮箱</label>
				<div class="layui-input-block">
					<input type="text" id="applyEmail" name="applyEmail" lay-verify="required|email"
						placeholder="请输入负责人姓名" autocomplete="off" class="layui-input">
				</div>
			</div>
			
			<div class="layui-form-item">
				<div class="layui-form-item layui-form-text">
				    <label class="layui-form-label">地址</label>
				    <div class="layui-input-block">
				      <textarea placeholder="请输入内容" class="layui-textarea" id="applyAdr" name="applyAdr"></textarea>
				    </div>
				</div>
			</div>
			
			<input type="hidden" id="departBy" name="departBy" value="${staff.staffName }">
			<div class="layui-input-block">
		        <button class="layui-btn" lay-submit lay-filter="demo">立即提交</button>
		        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		    </div>
		</form>
		
		<script type="text/javascript">
			var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
			
			var applyId;
			
			$(function (){
				applyId = GetQueryString("applyId");
				if(applyId!=null){
					findById(applyId);
				}
			});
			
			var form;
			layui.use(['form'], function() {
				form = layui.form;
				//监听提交
				form.on('submit(demo)', function(data){
					var data = $("#Apply").serialize();
					var url = "apply/addOrUpdate.action";
					var loadIndex = layer.load();
					$.post(url, data, function(mes){
						parent.layer.msg(mes.mes);
						
						layer.close(loadIndex);//加载层关闭  
						parent.layer.close(index);
						parent.table.reload("applyId");
					});
					return false;
				});
				
			});
			
			function findById(applyId){
				$.ajax({
					type: "POST",
					url: "apply/showApply.action",
					data: {"applyId":applyId},
					async: false,
					error: function(){
						layer.mes("发生未知错误，请稍后再试！");
					},
					success: function(obj){
						$("#applyId").val(obj.applyId);
						$("#applyNumber").val(obj.applyNumber);
						$("#applyName").val(obj.applyName);
						$("#applyBoss").val(obj.applyBoss);
						$("#applyAdr").val(obj.applyAdr);
						$("#applyPhone").val(obj.applyPhone);
						$("#applyEmail").val(obj.applyEmail);
					}
				});
			}
			
			/**
			得到URL栏的参数
			*/
			function GetQueryString(name){
			     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
			     var r = window.location.search.substr(1).match(reg);
			     if(r!=null)return  unescape(r[2]); return null;
			}
		</script>
	</body>
</html>